package com.sy.service.impl;

import com.sy.bean.PackageBean;
import com.sy.common.crud.BaseServiceImpl;
import com.sy.mapper.PackageBeanMapper;
import com.sy.service.PackageBeanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class PackageBeanServiceImpl extends BaseServiceImpl<PackageBean,PackageBeanMapper> implements PackageBeanService{
    @Autowired
    PackageBeanMapper packageBeanMapper;

    @Transactional
    @Override
    public int save(List<PackageBean> list) {
        //删除传过来不包含对应id的数据
        packageBeanMapper.batchDelete(list);
        list.forEach(o->{
            //如果id大于0，即为修改
            if (o.getId()>0){
                packageBeanMapper.update(o);
            }else {
                //否则为新增
                packageBeanMapper.save(o);
            }
        });
        return 1;
    }

    @Override
    public List<PackageBean> query() {
        return packageBeanMapper.query();
    }
}
